$libfx0 = @"
    public delegate void NAG_D01_FUN(ref double output);
    [DllImport("libfx0.dll", CharSet=CharSet.Auto, SetLastError=true)]
        public static extern void CallBack(NAG_D01_FUN f, ref double output);
"@ 

Add-Type -MemberDefinition $libfx0 -Namespace fx0 -Name "st_fx"

Function f([ref]$output)
{
    ### 参数作用范围仅在ScriptBlock作用域内部，函数返回时不发生改变
    ### 如果需要通过参数返回事务逻辑的处理结果，必须在C触发函数中明确赋值
    Write-Host "In PWSH-Function, parameter's value before process: "$output.Value
    $output.Value = 9.3
    Write-Host "In PWSH-Function, parameter's value after process: "$output.Value
}

#$Out=New-Object double @(0.0)
[double]$Out=0.0;

<#
[System.Management.Automation.ScriptBlock]$f_delegate = ${function:f}
$F = [fx0.st_fx+NAG_D01_FUN].GetMethod("NAG_D01_FUN")
$F = $f_delegate
#>

[fx0.st_fx+NAG_D01_FUN]$F = ${function:f}

[fx0.st_fx]::CallBack($F, [ref]$Out)

Write-Host "Original variable's value: "$Out
